import request from './request'

// 分页查询设施设备
export function getFacilityPage(params) {
  return request({
    url: '/api/facilities',
    method: 'get',
    params
  })
}

// 获取设施设备详情
export function getFacilityDetail(id) {
  return request({
    url: `/api/facilities/${id}`,
    method: 'get'
  })
}

// 添加设施设备
export function addFacility(data) {
  return request({
    url: '/api/facilities',
    method: 'post',
    data
  })
}

// 更新设施设备
export function updateFacility(id, data) {
  return request({
    url: `/api/facilities/${id}`,
    method: 'put',
    data
  })
}

// 删除设施设备
export function deleteFacility(id) {
  return request({
    url: `/api/facilities/${id}`,
    method: 'delete'
  })
}

// 获取所有设备类型
export function getAllFacilityTypes() {
  return request({
    url: '/api/facilities/types',
    method: 'get'
  })
}

// 获取设备统计信息
export function getStatistics() {
  return request({
    url: '/api/facilities/statistics',
    method: 'get'
  })
}

// 分页查询设备维护记录
export function getMaintenancePage(params) {
  return request({
    url: '/api/maintenance',
    method: 'get',
    params
  })
}

// 获取设备维护记录详情
export function getMaintenanceDetail(id) {
  return request({
    url: `/api/maintenance/${id}`,
    method: 'get'
  })
}

// 添加设备维护记录
export function addMaintenance(data) {
  return request({
    url: '/api/maintenance',
    method: 'post',
    data
  })
}

// 更新设备维护记录
export function updateMaintenance(id, data) {
  return request({
    url: `/api/maintenance/${id}`,
    method: 'put',
    data
  })
}

// 删除设备维护记录
export function deleteMaintenance(id) {
  return request({
    url: `/api/maintenance/${id}`,
    method: 'delete'
  })
}

// 获取设备最近的维护记录
export function getRecentMaintenanceRecords(facilityId, limit = 5) {
  return request({
    url: '/api/maintenance/recent',
    method: 'get',
    params: {
      facilityId,
      limit
    }
  })
}
